package com.tangdi;

import java.awt.print.PrinterJob;
import java.io.File;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.printing.PDFPrintable;
import org.apache.pdfbox.printing.Scaling;

public class UtilsPrintPDF_bak {
	public static String printPDF(String[] filePaths){
		try{
			PrinterJob job = PrinterJob.getPrinterJob();//java.awt.printerjob
	        boolean check_status = false;
	        check_status = job.printDialog();
	        if (check_status){
	        	for(int i = 0; i < filePaths.length; i++){
	        		boolean isExist = checkFileExist(filePaths[i]);
	        		if(isExist){

		        		PDDocument document = PDDocument.load(new File(filePaths[i]));
		        		//SCALE_TO_FIT  ACTUAL_SIZE
		                PDFPrintable printable = new PDFPrintable(document,Scaling.ACTUAL_SIZE);
		                //job.defaultPage(new PageFormat());
		                //job.setPageable(new PDFPageable(document));
		                job.setPrintable(printable);
		                job.print();
		                //System.out.println("job.getPrintService() " + job.getPrintService());
		                //System.out.println("job.getUserName() " + job.getUserName());
		                //System.out.println("job.getJobName() " + job.getJobName());
		                document.close();
		                }else{
		                	return "注意：" + filePaths[i] +" 文件不存在！";
		                	}
	        		}
	        	}else{
	        		return "取消打印！";
	        		}
	        }catch(Exception e){
				e.printStackTrace();
				return "打印过程出现异常！";
			}
		return "发送打印机成功！";
	}
	public static boolean checkFileExist(String filePath){
		File file = new File(filePath);
		if(!file.exists()){
		    return false;
		}
		return true;
	}

}
